import request from '@/utils/axios'
import assist from '@/utils/commonality'

/**
 * 
 * @param {手机号} phone 
 * @returns 
 */
export function verification(phone) { //发送验证码
  return request({
    url: '/login/captcha',
    method: 'get',
    params:{
      tel:phone
    }
  })
}


/**
 * 
 * @param {code跟tel} params 
 * @returns 
 */
export function login(params) { //通过验证码拿到uid
  return request({
    // url: 'login/phone',
    url: 'https://auth.server.sanwubeixin.cn/auth/login',
    method: 'get',
    params:{
      code: params.code, //验证码
      tel: params.tel, //手机号
      app_id: assist.getAppId(),
      version: assist.getVersion(),
      packet: assist.getPacket(),
      channel_id: assist.getChannelId(),
      other_id: assist.getOtherId(),
      os: assist.getOs(),
    }
  })
}

export function getUserUid() { //如果没有uid了 获取uid
  return request({
    url: '/login/login/other2uid',
    method:'GET',
    headers:{
      param: JSON.stringify({"oaid": '', "imei": ''}),
      "os": assist.getOs(),
      "version": assist.getVersion(),
      "app_id": assist.getAppId(),
      "packet": assist.getPacket(),
      "channel_id": assist.getChannelId(),
      "other_id": assist.getOtherId(),
      'Content-Type': 'application/json',
      'Access-Control-Allow-Origin': '*',
    },
      params: {
         mobile_os_version: ''
    },
  })
}



export async function getUserInfo() { //通过uid拿到用户信息
  return request({
    url: 'https://auth.server.sanwubeixin.cn/auth/info',
    method:'GET',
      params: {
        jwt:assist.jwt.get() ,
        app_id: assist.getAppId(),
        uid:await assist.getUid(),
        version: assist.getVersion(),
        packet: assist.getPacket(),
        channel_id: assist.getChannelId(),
        os: assist.getOs(),
        is_order: 1,
    },
  })
}


export function logoutApi() { //退出登录
  return request({
    url: '/login/out',
  })
}

